-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm32-wasi getpid() from wasi-libc #124554
Conversation
rustbot has assigned @workingjubilee. Use |
I don't think returning a useless value is any more conformant than the current implementation. |
As I understand, WASI cannot provide getpid ever.
Currently Rust std doesn't expose Thank you for the review! Please feel free to close PR if it doesn't fit in. |
Hmm. Basically, the premise of my understanding is that in C, we can't realistically do something spiteful and cruel like abort the process every time someone calls a function like
Currently, I'm trying to think of a situation where someone
Basically, I can't see how this doesn't end in "you do something else that's invalid on wasi", which is the case where we do in fact want to panic. |
I am also slightly concerned about future evolution smoothness, if wasi ever legalizes However, now that the wasi targets are known as preview targets, I think this is actually nominally okay. cc @sunfishcode (do you want to be listed as a wasi maintainer?) @alexcrichton I am interested to hear your perspectives on this, as you obviously have a stronger sense for why getpid was chosen to return this wrong answer and whether this API will ever be meaningful. |
These are all good points, and thanks for the PR @youknowone! Personally I'd be inclined to merge this myself. The main reason for this is that calls to functions like As for the history of the current implementation, I don't remember precisely but I believe the line of reasoning was probably:
For now it's not actually possible to recover from panics in wasm due to the lack of default support for exception handling, meaning that if you're using a library which internally calls this function you're out-of-luck and won't be able to make progress. Another point worth mentioning is that I don't think that Rust's More-or-less I don't think there's an obviously correct answer here. I'd lean towards matching wasi-libc because of how this low-level function seems likely to at least be used in an informational capacity deep in a library that's hard to excise for WASI. |
I'd like to ask if
wasi-libc seemed to add it for the same reason. In rust, this would be a slightly weaker reason than wasi-libc.
|
Oh, that's exceedingly fun then. Speaking of logging, I did start to think of that logging library example, and... you know, is there any chance wasi libc or something could generate a still-fake but more... "pid-looking" pid? Because if I was using logging infra distributed across wasm instances, and I keyed on the recorded pid for some reason, I would falsely correlate all of them, wouldn't I? I suppose the alternative of 1 is more "obviously wrong" at least. |
Hm so to me the plot is now thickening. Support for Given that wasi-libc by default doesn't support getpid I'd say that Rust should mirror that. Unfortunately Rust doesn't have a way to opt-in like wasi-libc does. To perhaps help better understand/resolve that, @youknowone could you elaborate a bit on the rationale for this PR? For example was there a library calling |
Oh, no. I screwed up testing. I didn't write a small test, I tested with the whole of my project. I thought the patch was working, but I realized I was using a workaround-patched version 🤦. I am really sorry for making trouble. With original code, no compile error but a runtime error.
Not a library but a project I am working on. That can be easily patched, so no problem. |
To confirm, with this PR I would expect a link-time error when building with a crate that uses If this is easy to work around for you then I think it might be best to stick to that course. One day we'll hopefully have the ability to easily remove the |
Cool! With the libc revert up then it looks like this thread has served its purpose and I will be closing this PR then! |
@alexcrichton No link-time error during build time. I don't see any error during build. I see runtime error, but not when running the code, but immediately after running wasmer:
|
Ah right yes excellent point, I forgot that unresolved symbols aren't linking errors but end up getting imported. Makes sense though, as that means that the symbol was indeed unresolved (and the environment shouldn't have to provide the symbol) |
No description provided.